package api

import (
	"github.com/gin-gonic/gin"
	"lisGin/lib"
	"lisGin/logic"
	"net/http"
)

// Login godoc
// @Summary 登录接口
// @Schemes
// @Description 用户登录接口
// @Tags user
// @Accept json
// @Produce json
// @Success 200 {object} lib.Response
// @Param params body logic.UserLogin true "登录参数"
// @Router /login [post]
func Login(c *gin.Context) {
	var loginParams logic.UserLogin
	if err := c.ShouldBindBodyWithJSON(&loginParams); err == nil {
		res := loginParams.Login()
		c.JSON(http.StatusOK, res)
	} else {
		c.JSON(http.StatusOK, lib.Fail(lib.ParamErrorCode, lib.ParamErrorMsg))
	}
}

func Register(c *gin.Context) {
	var registerParams logic.UserRegister
	if err := c.ShouldBindBodyWithJSON(&registerParams); err == nil {
		res := registerParams.Register()
		c.JSON(http.StatusOK, res)
	} else {
		c.JSON(http.StatusOK, lib.Fail(lib.ParamErrorCode, lib.ParamErrorMsg))
	}
}
